package main

import (
	"fmt"
	"time"
)

/*
   @Time : 2018/8/31 14:34 
   @Author : ff
   使用goroutine和channel实现并发
*/

func main() {
	//withbuff()
	notbuff()

	time.Sleep(10 * time.Second)
}

func f1(c chan int)  {
	fmt.Println("I am buff channel !")
	c<-0
}

/**
 	有缓冲的channel(先放后取)
 */
func withbuff()  {
	c := make(chan int,1)
	go f1(c)
	<-c
}

func f2(c chan int)  {
	fmt.Println("I am not buff channel !")
	<-c             //channel中没有值，goroutine在此阻塞
}

/**
 	无缓冲的channel(先取后放)
 */
func notbuff()  {
	c := make(chan int)
	go f2(c)
	c<-1000
}